package com.yksj.healthtalk.utils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentManager;

import com.yksj.healthtalk.entity.CustomerInfoEntity;
import com.yksj.healthtalk.net.http.CustomerInfoHttpResponseHandler;
import com.yksj.healthtalk.net.http.HttpRestClient;
import com.yksj.healthtalk.net.socket.SmartFoxClient;
import com.yksj.healthtalk.services.CoreService;
import com.yksj.healthtalk.ui.app.AppManager;
import com.yksj.healthtalk.ui.app.HTalkApplication;
import com.yksj.healthtalk.ui.friend.DoctorMainActivity;
import com.yksj.healthtalk.ui.friend.FriendInformUI;

public class ActivityUtils {
	
	
	public static void startWebView(Activity activity,String url){
		Uri uri = Uri.parse(url);
		Intent intent = new Intent(Intent.ACTION_VIEW,uri);
		activity.startActivity(intent);
	}
	
	/**
	 * 强制更新
	 * @param activity
	 */
	public static void forceUpdateApp(Context context){
		context.stopService(new Intent(context, CoreService.class));
		AppManager.getInstance().finishAllActivity();
		Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yijiankangv.com/sms_web/HealthTalk.apk"));
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
		try{
			Thread.sleep(800l);
		}catch(Exception e){
		}
		android.os.Process.killProcess(android.os.Process.myPid());
	}
	
	/**
	 * 跳转到客户资料
	 * @param activity
	 * @param manager
	 * @param id
	 */
	public static void startUserInfoActivity(Activity activity,FragmentManager manager,String id){
		CustomerInfoEntity entity = (CustomerInfoEntity)HTalkApplication.getAppData().cacheInformation.get(id);
		//内存中查找
		if(entity != null){
			if(entity.isShowDoctorV()){
				Intent intent = new Intent(activity,DoctorMainActivity.class);
				intent.putExtra("id", entity.getId());
				activity.startActivity(intent);
			}else{
				Intent intent = new Intent(activity,FriendInformUI.class);
				intent.putExtra("id", entity.getId());
				activity.startActivity(intent);
			}
		}else{
		//网络请求	
			final String userId = SmartFoxClient.getLoginUserId();
			HttpRestClient.doHttpFindCustomerInfoByCustId(null, null,id,null,new CustomerInfoHttpResponseHandler(activity,manager));
		}
	}
	
//	public static void startGroupChatting(Context context,GroupInfoEntity group,Map<String, ArrayList<String>> groupList,ChatUserHelper chatUserHelper){
//		String id = group.getId();
//		
//		CollectUtils.updateFriendRecent(context,groupList,Tables.TableFriend.TABLE_GROUP, id, R.string.recentGroup,chatUserHelper);
////		CollectUtils.updateFriendRecent(context,grouplist,DBUtils.TABLE_GROUP, id, R.string.recentGroup);
//		String recent = context.getResources().getString(R.string.recentGroup);
//		if(groupList.get(recent).contains(id)){
//			groupList.get(recent).remove(id);
//		}
//		groupList.get(recent).add(0,id);
//		
//		//DBUtils.saveOrUpdateRecentFriendInfo(context, group, SmartFoxClient.userId);
//		Intent i = new Intent(context, ChatActivity.class);
//		i.putExtra("id", id);
//		i.putExtra("isGroupChat", true);
//		i.putExtra("name",group.getName());
//		context.startActivity(i);
//	}
	
//	/**
//	 * 加入聊天室
//	 * @param value
//	 */
//	public static void joinGroupChat(Context context,GroupInfoEntity group,Map<String, ArrayList<String>> groupList,String value,ChatUserHelper chatUserHelper){
//		try {
//			JSONArray json = new JSONArray(value);
//			String flag = json.getString(0);
//			Toast.makeText(context, json.getString(1), Toast.LENGTH_SHORT).show();
//			if(flag.equals("1")){
//				ActivityUtils.startGroupChatting(context,group,groupList,chatUserHelper);
//			}
//		} catch (JSONException e) {
//			e.printStackTrace();
//		}
//	}
	
	

}
